package com.stox.validation;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.validation.Validator;

import com.stox.util.ApplicationContextUtil;

public class ValidationEntityListener {

    private Validator validator;

    private void init() {
        if (null == validator)
            validator = ApplicationContextUtil.getBean(Validator.class);
    }

    @PreUpdate
    @PrePersist
    public void validate(Object entity) {
        init();
        validator.validate(entity, new Class< ? >[0]);
    }

}
